forum

home / developersection / forums / make a post to url and get the response

Make a post to URL and get the response

Anonymous User 2061 03-Nov-2014

I try to post an XML file to the url and get the response back. I have this code to post. I am not really sure how to check if it is posting correctly and how to get the response.

WebRequest req = null;
            WebResponse rsp = null;
          //  try
          //  {
                string fileName = @"C:\ApplicantApproved.xml";
                string uri = "http://stage.test.com/partners/wp/ajax/consumeXML.php";
                req = WebRequest.Create(uri);

                req.Method = "POST";        // Post method
                req.ContentType = "text/xml; encoding='utf-8'";

                // Wrap the request stream with a text-based writer
                StreamWriter writer = new StreamWriter(req.GetRequestStream());
                // Write the XML text into the stream
                writer.WriteLine(this.GetTextFromXMLFile(fileName));
                writer.Close();
                // Send the data to the webserver
                rsp = req.GetResponse();

I think I should have the response in rsp but I am not seeing anything usufull on it.


Updated on 03-Nov-2014

I am a content writter !

Can you answer this question?

Answer

1 Answers

Liked By